package day8;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;


public class Demo {
	public static void main(String[] args) throws Exception {
    write();
	}

	public static void write() throws Exception {
		java.net.URL url = new java.net.URL("http://localhost:8081/day8/ServletDemo");
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		conn.setDoOutput(true);
		conn.setRequestProperty("xxx", "yyy");
		OutputStream outputStream = conn.getOutputStream();
		outputStream.write("name=xiya".getBytes());
		conn.getResponseCode();
	}

	public static void read() throws Exception {
		java.net.URL url = new java.net.URL("http://localhost:8081/day8/ServletDemo");
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		BufferedReader bReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		String content = bReader.readLine();
		System.out.println(conn.getResponseCode());
		System.out.println(conn.getHeaderField("Server"));
		System.out.println(content);

	}
}
